{include file="header"}
<div style="padding: 20px;" class="adminmyucms">
<form class="layui-form" action="">
  <div class="layui-form-item">
      <span style="float: left;line-height: 38px;margin: 0 20px;">名称</span>
	  <input type="text" name="title" value=""  placeholder="模型命名" autocomplete="off" lay-verify="required" class="layui-input" style="width: 150px;float: left;">
      <span style="float: left;line-height: 38px;margin: 0 20px;">表名</span>
	  <input type="text" name="name" value=""  placeholder="不能与现有的数据表重合" autocomplete="off" lay-verify="required" class="layui-input" style="width: 300px;float: left;">
    <button style="float: left;line-height: 38px;margin: 0 20px;" class="layui-btn layui-btn-warm" lay-submit lay-filter="set-add">添加模型</button>
    </div>
</form>
{foreach name=":fun_S('model',array(),'px desc','1000',1)" item="v" key="k"}
<form class="layui-form" action="">
<input type="hidden" name="id" value="{$v.id}">	
<table class="layui-table">
  <colgroup>
  	<col width="50">
  	<col width="50">
  	<col width="100">
  	<col width="200">
  	<col width="100">
  	<col width="100">
  	<col width="100">
  	<col width="50">
  	<col width="180">
    <col>
  </colgroup>
  <thead>
    <tr>
      <td>模型ID</td>
      <td>数据表</td>
      <td>名称</td>
      <td>描述</td>
      <td>前台显示</td>
      <td>付费阅读</td>
      <td>搜索模板</td>
      <td>排序</td>
      <td>操作</td>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>{$v.id}</td>
      <td>{$v.name}</td>
      <td><input type="text" name="title" value="{$v.title}" placeholder="请输入内容" autocomplete="off" class="layui-input"></td>
      <td><input type="text" name="describe" value="{$v.describe}" placeholder="请输入内容" autocomplete="off" class="layui-input"></td>
      <td>
       <select name="open" lay-verify="required">
        <option value=""></option>
        <option value="1" {if condition="$v['open'] eq 1"}selected="selected"{/if}>显示</option>
        <option value="0" {if condition="$v['open'] eq 0"}selected="selected"{/if}>不显示</option>
       </select>
      </td>
      <td>
       <select name="fufei" lay-verify="required">
        <option value=""></option>
        <option value="1" {if condition="$v['fufei'] eq 1"}selected="selected"{/if}>开启</option>
        <option value="0" {if condition="$v['fufei'] eq 0"}selected="selected"{/if}>关闭</option>
       </select>
      </td>
      <td>
      <select name="soso" lay-verify="required">
        <option value=""></option>
        {volist name=":Model('soso')" id="or"}
        <option value="{$or.mulu}" {if condition="$v['soso'] eq $or['mulu']"}selected="selected"{/if}>[{$or.mulu}]{$or.name}</option>
        {/volist} 
      </select>
      </td>
      <td><input type="number" name="px" value="{$v.px}" placeholder="请输入内容" autocomplete="off" class="layui-input"></td>
      <td>
      	<div class="layui-btn-group" id="admin_set">
     <button class="layui-btn layui-btn-normal layui-btn-sm" style="float: left;" lay-submit lay-filter="set"><i class="layui-icon">&#xe9aa;</i> 更新</button>
     <button class="layui-btn layui-btn-warm layui-btn-sm" data-method="admin_set" type="button" url="{:url("model/ziduan")}?id={$v.id}"><i class="layui-icon">&#xe642;</i>字段</button>
     <button type="button" class="layui-btn layui-btn-sm layui-btn-danger" lay-submit lay-filter="set-delete"><i class="layui-icon">&#xe640;</i> 删除</button>
     <button type="button" class="layui-btn layui-btn-sm layui-btn-danger" lay-submit lay-filter="set-deleteqc"><i class="layui-icon">&#xe640;</i> 清除</button>
</div>
      </td>
 
    </tr>
  </tbody>
</table>
</form>
{/foreach}
<script>
layui.use('form',function(){
  var form = layui.form
  ,jq = layui.jquery;

  //更新
  form.on('submit(set)', function(data){
    loading = layer.load(2, {
      shade: [0.2,'#000']
    });
    var param = data.field;
    jq.post('{:url("model/update")}',param,function(data){
      if(data.code == 1){
        layer.close(loading);
        layer.msg(data.msg, {icon: 1, time: 1000}, function(){
          //location.href = '{:url("index/index")}';
        });
      }else{
        layer.close(loading);
        layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
      }
    });
    return false;
  });
  //删除
  form.on('submit(set-delete)', function(data){
    var param = data.field;
        layer.confirm('确定删除? 删除当前数据表会删除,请备份好,删除前请慎重 ', function(index){
      loading = layer.load(2, {
        shade: [0.2,'#000']
      });
    jq.post('{:url("model/delete")}',param,function(data){
      if(data.code == 1){
        layer.close(loading);
        layer.msg(data.msg, {icon: 1, time: 1000}, function(){
          location.reload();
        });
      }else{
        layer.close(loading);
        layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
      }
    });
   }); 
    return false;
  });
  form.on('submit(set-deleteqc)', function(data){
    var param = data.field;
        layer.confirm('确定清除当前模型相关的数据吗? 包括用户点赞 文章 评论 等,清除前请慎重哦 ', function(index){
      loading = layer.load(2, {
        shade: [0.2,'#000']
      });
    jq.post('{:url("model/deleteqc")}',param,function(data){
      if(data.code == 1){
        layer.close(loading);
        layer.msg(data.msg, {icon: 1, time: 1000}, function(){
          location.reload();
        });
      }else{
        layer.close(loading);
        layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
      }
    });
   }); 
    return false;
  });
  //添加
  form.on('submit(set-add)', function(data){
    loading = layer.load(2, {
      shade: [0.2,'#000']
    });
    var param = data.field;
    jq.post('{:url("model/insert")}',param,function(data){
      if(data.code == 1){
        layer.close(loading);
        layer.msg(data.msg, {icon: 1, time: 1000}, function(){
          location.reload();
        });
      }else{
        layer.close(loading);
        layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
      }
    });
    return false;
  });
})
</script>
</div>  
{include file="footer"}